package servlet;

import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import model.Board;
import model.Quest;
import model.Study;
import DAO.BoardDao;
import DAO.StudyDao;
import DAO.UserDao;

public class BoardInfoAction implements Action {

	@Override
	public ActionForward execute(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		ActionForward forward=new ActionForward();
		Study study = new Study();
		StudyDao studyDao = new StudyDao();
		UserDao userDao = new UserDao();
		BoardDao boardDao = new BoardDao();
		Board board = new Board();
		 HttpSession session=request.getSession();
			
			
			int studyId = request.getParameter("studyId") != null
					&& request.getParameter("studyId") != "" ? Integer
					.parseInt(request.getParameter("studyId")) : 0;
			int userIdCheck = session.getAttribute("userid") != null
					&& session.getAttribute("userid") != "" ? Integer
					.parseInt((String)session.getAttribute("userid")) : 0;
			if (userIdCheck < 1) {
				session.invalidate();
				Util.ShowError(response, "로그인해주세요");
			}
			if (studyId < 1) {
				Util.ShowError(response, "잘못 된 접근입니다");
			}
			
		int boardId = request.getParameter("boardId")!=null
				&& request.getParameter("boardId") != ""?Integer.parseInt(request.getParameter("boardId")):0;
				
		request.setAttribute("studyId", studyId);
		
		if(boardId > 1)
		{
			
			board = boardDao.getBoardInfo(boardId);
			
			request.setAttribute("board", board);
				
				
			forward.setPath("./detailBoardInfo.jsp");
		
		}
		else{
			Util.ShowError(response, "잘못된접근입니다.");
		}
		return forward;
	
	}

}
